import os
import sys

from core.rest_client import RestClient
from common.read_data import data

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)
data_file_path = os.path.join(BASE_PATH, "config", "setting.ini")
api_root_url = data.load_ini(data_file_path)["host"]["api_root_url"]


class Ds(RestClient):

    def __init__(self, api_root_url, **kwargs):
        super(Ds, self).__init__(api_root_url, **kwargs)

    def nslist(self, **kwargs):
        '''
        获取数据源列表
        '''
        return self.get("/api/ds/nslist", **kwargs)

    def all(self,**kwargs):
        '''
        获取所有的可添加的数据源
        '''
        return self.get("/api/ds/all", **kwargs)

    def category(self, **kwargs):
        '''
        添加数据源
        '''
        return self.get("/api/ds/category", **kwargs)

    def delete(self, **kwargs):
        '''
        删除工作表
        '''
        return self.post("/api/tb/delete", **kwargs)

    def preview(self, **kwargs):
        '''
        浏览工作表
        '''
        return self.post("/api/tb/preview", **kwargs)


    def status(self, **kwargs):
        '''
        获取工作表状态
        '''
        return self.post("/api/tb/status", **kwargs)


    def info(self, **kwargs):
        '''
        获取工作表信息
        '''
        return self.get("/api/tb/info", **kwargs)


    def delete_batch(self, **kwargs):
        '''
        批量删除工作表
        '''
        return self.post("/api/tb/delete_batch", **kwargs)


    def chart_check(self, **kwargs):
        '''
        检查工作表是否关联了图表
        '''
        return self.post("/api/tb/chart_check", **kwargs)

    def list_check_rely(self, **kwargs):
        '''
        批量检查工作表是否有依赖
        '''
        return self.post("/api/tb/list_check_rely", **kwargs)



ds = Ds(api_root_url)
